package com.lunhui.map.provide.main.impl;

import com.alibaba.fastjson.JSONObject;
import com.lunhui.map.business.LunhuiMapService;
import com.lunhui.map.client.MapClient;
import com.lunhui.map.client.dto.MapInfoDto;
import com.lunhui.map.dal.model.MapSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author renminghe-kg
 */
@Service
public class MapClientImpl implements MapClient {

    private static final Logger logger = LoggerFactory.getLogger(MapClientImpl.class);

    @Autowired
    @Qualifier("lunhuiMapService")
    private LunhuiMapService lunhuiMapService;

    @Override
    public List<MapInfoDto> getMapInfo(int areaId, int sceneId) {

        List<MapInfoDto> mapInfoDtoList = new ArrayList<>();

        try
        {
            List<MapSource> mapInfo = lunhuiMapService.getMapInfo(areaId, sceneId);

            if (mapInfo != null) {

                mapInfo.forEach((entity) -> {
                    MapInfoDto mapInfoDto = new MapInfoDto();
                    BeanUtils.copyProperties(entity, mapInfoDto);

                    mapInfoDtoList.add(mapInfoDto);
                });

            }

        } catch (Exception e) {
            logger.error("获取地图信息失败: " + e.getMessage());
        }

        logger.info("地图信息: " + JSONObject.toJSONString(mapInfoDtoList));
        return mapInfoDtoList;
    }
}